package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;

public class MainActivity23 extends AppCompatActivity {

    private MotionLayout mRoot;
    private Button mWatch;
    private Button mMessage;

    private boolean watch = true;//记录是否关注

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity23.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main23 );
        initView();
        initViewAction();
    }

    private void initView() {

        mRoot = (MotionLayout) findViewById( R.id.root );
        mWatch = (Button) findViewById( R.id.watch );
        mMessage = (Button) findViewById( R.id.message );
    }

    private void initViewAction() {

        mRoot.setTransition( R.id.unWatch );

        mWatch.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                if ( mRoot.getCurrentState() != mRoot.getStartState() && mRoot.getCurrentState() != mRoot.getEndState() ) {
                    return;
                }

                if ( watch ) {
                    mRoot.transitionToState( R.id.end );
                    watch = false;
                } else {
                    mRoot.transitionToState( R.id.start );
                    watch = true;
                }
            }
        } );
    }
}